//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.woniuxy.user.web.controller;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.JwtUtil;
import com.woniuxy.core.util.PageInfo;
import com.woniuxy.core.util.RedisUtil;
import com.woniuxy.user.dao.UserInfo;
import com.woniuxy.user.model.form.LoadAllUserinfoForm;
import com.woniuxy.user.model.param.IdCard;
import com.woniuxy.user.model.param.LoadAllUserinfoParam;
import com.woniuxy.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@Api(
        tags = {"用户相关接口"}
)
@RequestMapping({"/userInfo"})
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private RedisUtil redisUtil;

    public UserInfoController() {
    }

    @ApiOperation("身份证识别以及新增个人信息")
    @GetMapping({"/VerifyIdCard"})
    @ApiImplicitParams({@ApiImplicitParam(name = "name",value = "真实姓名"),@ApiImplicitParam(name = "idcard",value = "身份证"),
            @ApiImplicitParam(name = "userInfoName",value = "昵称")})
    private Result VerifyIdCard(String name, String idcard,String userInfoName ,@RequestHeader String token) {
        String id = JwtUtil.parseUserToken(token).get("id").toString();
        System.out.println(id);
        IdCard idCard1 = this.userInfoService.VerifyIdCard(name, idcard, Integer.valueOf(id),userInfoName);
        return Result.getResult(IdCard.class).setMessage("身份证识别成功及添加个人信息成功").setData(idCard1);
    }

    @ApiOperation("修改个人信息(修改昵称以及电话)")
    @GetMapping({"/updateUserInfo"})
    @ApiImplicitParams({@ApiImplicitParam(name = "userinfoname",value = "昵称"),@ApiImplicitParam(name = "userinfotel",value = "用户电话")})
    private Result updateUserInfo(String userinfoname, String userinfotel, @RequestHeader String token) {
        String id = JwtUtil.parseUserToken(token).get("id").toString();
        System.out.println(id);
        userInfoService.updateUserInfo(userinfoname, userinfotel,Integer.valueOf(id));
        return Result.getResult(IdCard.class).setMessage("修改个人信息成功");
    }



    @ApiOperation("根据id查询用户详细信息")
    @GetMapping("/loadAllUserinfobyId")
    @ApiImplicitParam(name = "userInfoId",value = "用户id")
    public Result<UserInfo> loadAllUserinfobyId(Integer userInfoId){
        System.out.println(userInfoId);
        UserInfo userInfo = userInfoService.loadAllUserinfobyId(userInfoId);
        return Result.getResult(UserInfo.class).setMessage("根据id查询业主信息成功").setData(userInfo);
    }

    @ApiOperation("查询用户详细信息")
    @GetMapping("/loadAllUserinfos")
    public Result<UserInfo> loadAllUserinfos(@RequestHeader String token){
        String id = JwtUtil.parseUserToken(token).get("id").toString();
        System.out.println(id);
        UserInfo userInfo = userInfoService.loadAllUserinfos(id);
        return Result.getResult(UserInfo.class).setMessage("查询业主信息成功").setData(userInfo);
    }

    @ApiOperation("查询用户是否实名认证")
    @GetMapping("/loadAllUserinfoss")
    public Result<Boolean> loadAllUserinfoss(@RequestHeader String token){
        String id = JwtUtil.parseUserToken(token).get("id").toString();
        System.out.println(id);
        Boolean aBoolean = userInfoService.loadAllUserinfoss(id);
        System.out.println("aaaaa");
        System.out.println(aBoolean);
        return Result.getResult(Boolean.class).setData(aBoolean).setCode(200).
                setMessage("验证用户实名认证成功");
    }
    @ApiOperation("查询用户是否实名认证(服务间调用)")
    @GetMapping("/loadAllUserinfosss")
    public Result<Boolean> loadAllUserinfosss(String id){
        Boolean aBoolean = userInfoService.loadAllUserinfoss(id);
        return Result.getResult(Boolean.class).setData(aBoolean).setCode(200).
                setMessage("验证用户实名认证成功");
    }

    @ApiOperation("分页查询所有用户信息")
    @GetMapping("/loadAllUserinfo")
    public Result<PageInfo> loadAllUserinfo(LoadAllUserinfoForm laf){
        LoadAllUserinfoParam param = BeanUtil.toBean(laf, LoadAllUserinfoParam.class);
        PageInfo<UserInfo> pageInfo = userInfoService.loadAllUserinfo(param);
        return Result.getResult(PageInfo.class).setMessage("分页查询所有用户信息成功").setData(pageInfo);
    }

    @ApiOperation("修改用户头像")
    @PostMapping("/uploadImage")
    public Result<String> uploadImage(MultipartFile image,@RequestHeader String token) throws IOException {
        String id = JwtUtil.parseUserToken(token).get("id").toString();
        String url = String.valueOf(userInfoService.uploadImage(image,id));
        return Result.getResult(String.class).setMessage("修改用户头像成功").setData(url);
    }


    @ApiOperation("根据姓名查询用户")
    @GetMapping("/loadAllUserinfobyName")
    @ApiImplicitParam(name = "userRealName",value = "用户姓名")
    public Result<UserInfo> loadAllUserinfobyName(String userRealName){
        UserInfo userInfo = userInfoService.loadAllUserinfobyName(userRealName);
        return Result.getResult(UserInfo.class).setMessage("根据姓名查询用户信息成功").setData(userInfo);
    }


    @ApiOperation("根据手机号查询用户")
    @GetMapping("/loadAllUserinfobyUserPhone")
    @ApiImplicitParam(name = "userphone",value = "用户电话")
    public Result<UserInfo> loadAllUserinfobyUserPhone(String userphone){
        UserInfo userInfo = userInfoService.loadAllUserinfobyUserPhone(userphone);
        return Result.getResult(UserInfo.class).setMessage("根据手机号查询用户信息成功").setData(userInfo);
    }


}
